<?php
ob_start();
session_start();

function __autoload($class_name) {
include './'.$class_name . '.php';
}

$cart = $_SESSION['cart'];
$shoppingcart = NULL;
if(is_null($cart)){
		$shoppingcart = '{"ordercount":"0"}';	
	}
else{
		$count = $cart -> countOrder();
		$orderList = $cart -> getOrderList();
		$shoppingcart = "{\"ordercount\":\"".$count."\",\"order\" :[";
		for ($i = 0; $i < $count; $i++) {
			$myOrder = $orderList[$i];
				
			$shoppingcart = $shoppingcart."{\"productid\":\"".$myOrder->getProductId()."\",";
			$shoppingcart = $shoppingcart."\"productname\":\"".$myOrder->getProductName()."\",";	
			$shoppingcart = $shoppingcart."\"categoryid\":\"".$myOrder->getCategoryId()."\",";
			$shoppingcart = $shoppingcart."\"quantity\":\"".$myOrder->getQuantity()."\",";
			if($i != ($count-1)){
				$shoppingcart = $shoppingcart."\"rate\":\"".$myOrder->getRate()."\"},";	
			}else {
				$shoppingcart = $shoppingcart."\"rate\":\"".$myOrder->getRate()."\"}";	
			}
		}
		$shoppingcart = $shoppingcart."]}";

	}	
echo $shoppingcart;
ob_end_flush();
?>
